from annoying.decorators import render_to
from django.shortcuts import get_object_or_404

from core.models import Event, User, Participation
from core.views.event.strategies_calculation import check_patrons
from core.lib import is_user_authenticated

@render_to('event/details.html')
def details(request, id):
    event = get_object_or_404(Event, id=id)
    strategy = event.strategy.id
    with_patron = check_patrons(strategy)
    cost_status = True
    if is_user_authenticated(request):
        user = User.objects.get(id=request.session['user_id'])
        try:            
            investment = Participation.objects.get(event=event, user=user).investment
            cost_status = False if investment < event.current_sum_for_user else True   
        except:
            pass
    return {'event': event, 'cost_status': cost_status, \
            'with_patron': with_patron, 'Status': Event.Status}